/*-+-*****************************************************************************
 Copyright (C) 2009-2012 Oceanside Software Corporation (R)
 Dallas, Texas

 Author       : Jason T. Brower
 Purpose      : This file is part of a point-of-sale software package
                originally written for Table-Service Restaurants.
              
 Date         : July 8th of 2012
              
 History      : The application that this software file belongs to was 
                written over a 3-Year period.  The first version was written
                in C# .Net 3.5 using Windows Forms.  Being new to .Net at
                the time, I soon learned of Windows Presentation Foundation,
                liked the graphics capabilities and databinding so I
                migrated to WPF.  When the .Net 4.0 framework was released
                the application was migrated from 3.5 to 4.0. Now today,
                .Net 4.5 RC is out and I was already in process of migrating
                before I made this public.
                
Excuse Me     : Please excuse the coding style, it is not representative of
                my typical work.  During the three years I was under a very
                tight budget, constantly running out of funding and was 
                working 18 hour days hyped up on 5-Hour Energy.  The 
                design is not textbook.  It is monolythic because of
                previous issues I will not get into.  There are few comments
                in the code and the ones that are there may be incorrect.
                
What it is not: This is not the exact version that I took through PA-DSS 2.0
                nor is it the exact version running at my customer sites.
                I removed some details for security purposes including some
                encryption algorithms.  The reporting was removed because
                I was including a third party library that cannot be 
                published with this Open Source.
                
What it is    : This application has been running at high volume restaraunts
                for over a year.  It never freezes, crashes or does anything
                unexpected.  So long as it is built, installed and configured
                correctly, it is a strong system that we can all enhance.

Contact       : Please note that I can no longer work for free.  However, you
                can reach me at information@oceansidesw.com.                                                      

*********************************************************************************/
using System.Windows.Controls;
using System.Windows.Media;

#if _LOCALDB
  using Oceanside.LocalDB;
#else
using Oceanside.RemoteDB;
#endif
namespace Oceanside
{
    /// <summary>
    /// </summary>
    public partial class ReportsWindow : PosWindow
    {
        /// <summary>
        /// 
        /// </summary>
        private ReportsWindow()
            : base()
        {
            InitializeComponent();
            this.Height = PosWindow.MainPosWindow.Height;
            this.Width = PosWindow.MainPosWindow.Width;

            this.bComp1.ChangeButtonColor(Button_164_62.COLORS.RED);
            this.bComp2.ChangeButtonColor(Button_164_62.COLORS.RED);
            this.bComp3.ChangeButtonColor(Button_164_62.COLORS.RED);
            this.bComp4.ChangeButtonColor(Button_164_62.COLORS.RED);
            this.bComp5.ChangeButtonColor(Button_164_62.COLORS.RED);
            this.bComp6.ChangeButtonColor(Button_164_62.COLORS.RED);
            this.bComp7.ChangeButtonColor(Button_164_62.COLORS.RED);
            this.bComp8.ChangeButtonColor(Button_164_62.COLORS.RED);
            this.bComp9.ChangeButtonColor(Button_164_62.COLORS.RED);

            this.bSales1.ChangeButtonColor(Button_164_62.COLORS.GREEN);
            this.bSales2.ChangeButtonColor(Button_164_62.COLORS.GREEN);
            this.bSales3.ChangeButtonColor(Button_164_62.COLORS.GREEN);
            this.bSales4.ChangeButtonColor(Button_164_62.COLORS.GREEN);
            this.bSales5.ChangeButtonColor(Button_164_62.COLORS.GREEN);
            this.bSales6.ChangeButtonColor(Button_164_62.COLORS.GREEN);
            this.bSales7.ChangeButtonColor(Button_164_62.COLORS.GREEN);
            this.bSales8.ChangeButtonColor(Button_164_62.COLORS.GREEN);

            this.bMisc1.ChangeButtonColor(Button_164_62.COLORS.BLUE);
            this.bMisc2.ChangeButtonColor(Button_164_62.COLORS.BLUE);
            this.bMisc3.ChangeButtonColor(Button_164_62.COLORS.BLUE);
            this.bMisc4.ChangeButtonColor(Button_164_62.COLORS.BLUE);
            this.bMisc5.ChangeButtonColor(Button_164_62.COLORS.BLUE);
            this.bMisc6.ChangeButtonColor(Button_164_62.COLORS.BLUE);
        }

        static ReportsWindow singleton = null;
        static ReportsWindow()
        {
            singleton = new ReportsWindow();
        }

        public static void ShowFunctionButtons(bool isVisible)
        {
            if (isVisible)
            {
                singleton.wrapPanelFunctions.Visibility = System.Windows.Visibility.Visible;
                singleton.mainStackPanel.Height = 500;
            }
            else
            {
                singleton.wrapPanelFunctions.Visibility = System.Windows.Visibility.Hidden;
                singleton.mainStackPanel.Height = 627;
            }
        }

        public static bool IsInViewerMode()
        {
            if (singleton.wrapPanelFunctions.Visibility == System.Windows.Visibility.Hidden)
                return true;
            else
                return false;
        }
        private static System.Action prepareForScreenChangeAction;
        public static System.Action PrepareForScreenChangeAction
        {
            get { return prepareForScreenChangeAction; }
            set { prepareForScreenChangeAction = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public static StackPanel MainStackPanel
        {
            get { return singleton.mainStackPanel; }
        }

        /// <summary>
        /// 
        /// </summary>
        public static UserControl CustomControl
        {
            get;
            set;
        }

        public static void RemoveCustomControl()
        {
            if (CustomControl != null && MainStackPanel.Children.Contains(CustomControl))
            {
                MainStackPanel.Children.Remove(CustomControl);
                CustomControl = null;
                //ReportViewer.CleanMemory();
            }
        }

        private static System.Action prepareForScreenLeaveAction;
        public static System.Action PrepareForScreenLeaveAction
        {
            get { return prepareForScreenLeaveAction; }
            set { prepareForScreenLeaveAction = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public static WrapPanel PanelFunctions
        {
            get { return singleton.wrapPanelFunctions; }
        }


        /// <summary>
        /// 
        /// </summary>
        public override void PrepareForScreenChange()
        {
            //TODO this is not pretty.
            SystemMonitor._idOfReportRequester = SHIFT.Current.UserId;
            //END TODO

            ShowFunctionButtons(true);
            PrepareForScreenChangeAction();
        }

        /// <summary>
        /// 
        /// </summary>
        public override void PrepareForScreenLeave()
        {
            PrepareForScreenLeaveAction();
        }

        /// <summary>
        /// 
        /// </summary>
        public static void Show()
        {
            SwitchWindowDelegate_NOTHROW(singleton);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="o"></param>
        public static void AssignDataContext(object o)
        {
            singleton.DataContext = o;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="tc"></param>
        public static void AddInstanceToTabControl(ref TabControl tc)
        {
            tc.Items.Add(singleton);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="index"></param>
        public static void SetTabIndex(int index)
        {
            singleton.MyTabIndex = index;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            try
            {
                e.Handled = true;
                UserControl uc = sender as UserControl;
                int index = System.Convert.ToInt32(uc.Tag);
                PosWindow.ReportListBoundFunctions[index].Clicked();
            }
            catch (System.Exception ex)
            {
                Constants.ErrorDispatcher.Notify(Error.EType.E_LVBIND_CALL_BOUND_FUNC, ex);
            }
        }
    }
}
